package com.ywl5320.snowrain;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ywl5320.snowrain.flakeview.FlakeView;

public class MainActivity extends Activity {

	private TextView tvPlay;
	private FlakeView flakeView;
	private RelativeLayout lyContent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		tvPlay = (TextView) findViewById(R.id.tv_play);
		lyContent = (RelativeLayout) findViewById(R.id.ly_content);
		flakeView = new FlakeView(this);
		lyContent.addView(flakeView);
		tvPlay.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			//	lyContent.setVisibility(View.VISIBLE);
				handlerRain.postDelayed(runnableRain, 0);
			}
		});
	}
	
	Handler handlerRain = new Handler();
	Runnable runnableRain = new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			flakeView.addFlakes(15);
			handlerRain.postDelayed(runnableRain, 2000);
			if(flakeView.getNumFlakes() > 70)
			{
				handlerRain.removeCallbacks(runnableRain);
			}
		}
	};
}
